package com.example.springboot.util;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.stereotype.Component;

/**
 * @Description: KafkaUtil
 * @Author wenlinyu
 * @Date: 2020/12/17 16:05
 * @Version 1.0
 */
@Component
@EnableAsync
public class KafkaUtil {

    @Autowired
    private KafkaTemplate<String, String> kafkaTemplate;

    @Async
    public void send(String topic, String data){
        kafkaTemplate.send(topic, data);
    }

    @Async
    public void send(String topic, String key, String data){
        kafkaTemplate.send(topic, key, data);
    }

    @Async
    public void send(String topic, Integer partition, String key, String data) {
        kafkaTemplate.send(topic, partition, key, data);
    }

    @Async
    public void send(String topic, Integer partition, Long timestamp, String key, String data) {
        kafkaTemplate.send(topic, partition, timestamp, key, data);
    }
}
